Overview

This code will provide information on oil spills and their location throughout California State. A t-map will be produced as an interactive mode of exploring the data and a second static choropleth graph will be used to show a larger picture of the data within each county.

Citation

California Department of Fish and Game & Office of Spill Prevention and Response. (20089, July 23). Oil Spill Incident Tracking. Digital map and vector digital data. https://map.dfg.ca.gov/metadata/ds0394.html#ID0EUGA

knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

# attach packages
library(tidyverse)
library(here)
library(maptools)
library(sf)
library(tmap)
library(tmaptools)
library(janitor)

California Oil Spill Maps

T-map

oil_spills_sf <- read_sf(here("data/ds394/ds394.shp")) %>% 
  clean_names() %>% 
  st_transform(3310)

ca_counties <- read_sf(here("data/CA_Counties/CA_Counties_TIGER2016.shp")) %>% 
  clean_names() %>% 
  st_transform(3310)

tmap_mode(mode = "view")
tmap_options(check.and.fix = TRUE,
             max.categories = 58)

tm_shape(ca_counties) +
  tm_fill("aland", 
          palette = "BuGn", 
          popup.vars = c("County:" = "namelsad")) +
  tm_borders(col = "black") +
tm_shape(oil_spills_sf) +
  tm_dots(popup.vars = c("Control Number:" = "oesnumber", 
                         "Date:" = "dateofinci", 
                         "Time:" = "timeofinci", 
                         "County:" = "localecoun", 
                         "City:" = "localecity", 
                         "Type of Water:" = "specificlo",
                         "Inland or Marine:" = "inlandmari"),
          size = 0.02)

Figure 1. Interactive Map Showing Locations of Oil Spills within California State. For each oil spill location, the user may click on the point to receive more information including the data, time, and location.

Choropleth Map

ca_oil <- ca_counties %>% 
  st_join(oil_spills_sf) %>% 
  select(latitude, longitude, namelsad) %>% 
  group_by(namelsad) %>% 
  summarize(oil_spills = n())

ggplot(data = ca_oil) +
  geom_sf(aes(fill = oil_spills)) +
  scale_fill_gradient(low = "steelblue1", high = "dodgerblue4") +
  labs(title = "Choropleth Map of Oil Spills by \nCounty in California State",
       x = "Longitude",
       y = "Latitude",
       fill = "Oil Spill Number") +
  theme(plot.title = element_text(hjust = 0.5))

Figure 2. Choropleth Map of Oil Spills by County in California State. The colors indicate the number of oil spills that have occurred in each county.